﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Popups
{
    public partial class Scheduler : Form
    {
        public Scheduler()
        {
            InitializeComponent();
        }

        public DialogResult ShowInputDialog()
        {
            Scheduler dialog = new Scheduler();
            return dialog.ShowDialog();
        }

        private void btnSaveScheduler_Click(object sender, EventArgs e)
        {
            string strTESTSUITE = comboBoxTESTSUITE.SelectedValue.ToString().ToLower();
            string strRUNSETUP = comboBoxRUNSETUP.SelectedValue.ToString().ToLower();
            string strAUTORUN = "";
            string strAutoRunBeingSaved = Repository.SchedulerUtil.getAutoRun();
            if (strAutoRunBeingSaved.Trim().ToLower().Equals("no"))
            {
                strAUTORUN = "yes";
            }
            else
            {
                strAUTORUN = "no";
            }
            Repository.SchedulerUtil.setAUTORUN(strAUTORUN);
            Repository.SchedulerUtil.setTESTSUITE(strTESTSUITE);
            Repository.SchedulerUtil.setRUNSETUP(strRUNSETUP);

            //Close
            Close();
        }

        private void Scheduler_Load(object sender, EventArgs e)
        {
            //TESTSUITE
            comboBoxTESTSUITE.DisplayMember = "FileName";
            comboBoxTESTSUITE.ValueMember = "FileName";
            try
            {
                comboBoxTESTSUITE.DataSource = Repository.TestSuiteUtil.buildTestSuiteList();
            }
            catch (Exception ex)
            {
                Utilities.GlobalObject.LOGGER.log("Failed to load ListBox SCHEDULER.TESTSUITE Utilities.GlobalInit.buildTestSuiteDataTable()");
                Utilities.GlobalObject.LOGGER.log(ex.ToString());
            }
            
            //RUNSETUP
            DataTable DT = new DataTable();
            DT.Columns.Add(new DataColumn("options", typeof(string)));

            DataRow DR = DT.NewRow();
            DR[0] = "NO";
            DT.Rows.Add(DR);

            DR = DT.NewRow();
            DR[0] = "YES";
            DT.Rows.Add(DR);

            comboBoxRUNSETUP.DisplayMember = "options";
            comboBoxRUNSETUP.ValueMember = "options";
            comboBoxRUNSETUP.DataSource = DT;

            //BUTTON CHANGE
            string strAutoRun = Repository.SchedulerUtil.getAutoRun();
            if (strAutoRun.Trim().ToLower().Equals("no"))
            {
                btnSaveScheduler.Text = "Set ON and SAVE";
                btnSaveScheduler.ForeColor = Color.Blue;
            }
            else
            {
                btnSaveScheduler.Text = "Set OFF and SAVE";
                btnSaveScheduler.ForeColor = Color.Green;
            }
        }
    }
}
